package com.simblog.common.utils;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.simblog.oaknt.domain.User;


public class RedisUtil {
	
	public RedisTemplate<String, String> template;
	
	public RedisTemplate<String, String> getTemplate() {
		return template;
	}

	public void setTemplate(RedisTemplate<String, String> template) {
		this.template = template;
	}

	public void set(String key,Object object){
		String value  = JSON.toJSONString(object);
		template.opsForValue().set(key, value);
	}
	
	public JSONObject get(String key){
		String value = template.opsForValue().get(key);
		if(StringUtils.isBlank(value)){
			return null;
		}
		return JSONObject.parseObject(value);
	}
	
	public void delete(String key){
		template.delete(key);
	}
}
